<template>
  <div class="dashboard-container">
    <div class="dashboard-title">
      <el-button type="success" round size="mini" @click="save">提交</el-button>
    </div>

    <div id="editor" ref="editor" class="dashboard-editor">
      <p>Hello World!</p>
      <p>Some initial <strong>bold</strong> text</p>
    </div>
  </div>
</template>

<script>
import 'quill/dist/quill.snow.css'
import Quill from 'quill'

export default {
  name: 'Dashboard',
  data() {
    return {
      toolbar: [
        ['bold', 'italic'],
        ['link', 'blockquote', 'code-block', 'image'],
        [{ list: 'ordered' }, { list: 'bullet' }]
      ],
      quill: null
    }
  },
  mounted() {
    this.quill = new Quill(this.$refs.editor, {
      theme: 'snow',
      modules: {
        toolbar: this.toolbar
      },
      placeholder: '请输入正文'
    })
  },
  created() {},
  methods: {
    save() {
      const contents = this.quill.getContents()
      let content = ''
      contents.forEach((element) => {
        content += element.insert
      })
      console.log(contents)
      console.log(content)
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-title {
    float: right;
    right: 30px;
    position: absolute;
    margin: 6px;
  }
  &-editor {
    height: 75vh;
  }
}
</style>
